package com.uenpay.im.ui.old.activity.publicnumber;

import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;


/**
 * @author SL
 * @created 2016-1-8 下午2:04:40
 * @copyRight http://www.qiyunxin.com
 * @function 搜索公众号
 */
public class SearchPublicNumberListInvokeItem extends BaseHttpInvokeItem {
	public class SearchPublicNumberListInvokeItemResult extends
			HttpInvokeResult {
		public ArrayList<PublicNumEntity> arrayList = new ArrayList<PublicNumEntity>();
	}

	public SearchPublicNumberListInvokeItemResult getOutput() {
		return (SearchPublicNumberListInvokeItemResult) GetResultObject();
	}

	public SearchPublicNumberListInvokeItem(int page, String keyWord) {
		String url = APIConfiguration.getBaseUrl()
				+ "PublicNo/PublicNo/search?pageIndex=" + page
				+ "&pageSize=12&searchKey=" + keyWord + "&"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		SearchPublicNumberListInvokeItemResult result = new SearchPublicNumberListInvokeItemResult();
		JSONObject json = null;
		try {
			json = new JSONObject(responseBody);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		if (json == null) {
			return null;
		}
		result.status = json.optInt("status");
		result.msg = json.optString("msg");
		if (result.status != 0) {
			return result;
		}
		result.arrayList = DesPublicNumEntity.desEntities(json
				.optJSONArray("data"));
		return result;
	}
}
